<?
	// Vypnutie logovania - FUNGUJE
	// http://www.orafaq.com/wiki/Nologging_and_force_logging
	// NOLOGGING
	
	// Vypnutie relacnej integrity - NEZISTENE AKO TO FUNGUJE, ALE INDEXY ZAPINAM A VYPINAM "MANUALNE
	// The fact that "NO ACTION" and "RESTRICT" should be treated equally means that there is no way to delete a parent row without deleting the child row unless you disable the foreign key check. This is normally what we want, but there might be exceptions where it makes sense to keep an orphan row, e.g., when you have a "history" table that maintains some information about records that can be safely deleted.
	
	// Vypnutie indexovania - RIESI SA TO V RAMCI PRIKAZU INSERT INTO
	// http://bugs.mysql.com/bug.php?id=14709
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ETL ODS2DWH</title>
</head>
<body>
<?php
	$connection = mysql_pconnect('147.175.187.53', 'root', 'qwerty123', 65536);
	if (!$connection) {
		echo('<h3 style="color: Red;">Cannot connect to MySQL server &nbsp;&nbsp; :\'(</h3>');
		die('Could not connect: ' . mysql_error());
		exit(0);
	}
	mysql_query("SET NAMES 'utf8'");

	mysql_select_db("ods", $connection);

	$process = false;
	$vynimka = true;
	$truncateAndInsert = true;
	
	echo "bgn " . date("i:s:u") . "<br/>";
	if (true) {			// VYHODIME INDEXY
		echo "disabling indexes ...";
		{	//EXAMFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`examfacts`
					DROP FOREIGN KEY `fk_ExamFacts_Terms1` ,
					DROP FOREIGN KEY `fk_ExamFacts_Student1` ,
					DROP FOREIGN KEY `fk_ExamFacts_Room1` ,
					DROP FOREIGN KEY `fk_ExamFacts_ExamType1` ,
					DROP FOREIGN KEY `fk_ExamFacts_Course1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//SESSIONFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`sessionfacts`
					DROP FOREIGN KEY `fk_SessionFacts_UserAccount1` ,
					DROP FOREIGN KEY `fk_SessionFacts_Time2` ,
					DROP FOREIGN KEY `fk_SessionFacts_Time1`,
					DROP FOREIGN KEY `fk_SessionFacts_Room1` ,
					DROP FOREIGN KEY `fk_SessionFacts_Computer1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//COMPUTER
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`computer`
					DROP FOREIGN KEY `fk_Computer_Room1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//AGGREGATERATINGS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`aggregateratings`
					DROP FOREIGN KEY `fk_AggregateRatings_Term2` ,
					DROP FOREIGN KEY `fk_AggregateRatings_Term1` ,
					DROP FOREIGN KEY `fk_AggregateRatings_Student1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//BORROWINGFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`borrowingfacts`
					DROP FOREIGN KEY `fk_BorrowingFacts_Time2` ,
					DROP FOREIGN KEY `fk_BorrowingFacts_Time1` ,
					DROP FOREIGN KEY `fk_BorrowingFacts_LibraryAccount1` ,
					DROP FOREIGN KEY `fk_BorrowingFacts_Library1` ,
					DROP FOREIGN KEY `fk_BorrowingFacts_Book1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//USERACCOUNT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`useraccount`
					DROP FOREIGN KEY `fk_UserAccount_Student1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//STUDENT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`student`
					DROP FOREIGN KEY `fk_Student_StudyStatus1` ,
					DROP FOREIGN KEY `fk_Student_FieldOfStudy1`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//LIBRARYACCOUNT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`libraryaccount`
					DROP FOREIGN KEY `fk_LibraryAccount_Time1` ,
					DROP FOREIGN KEY `fk_LibAccount_Student`
				;
			" ;
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		{	//LIBRARY
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`library`
					DROP FOREIGN KEY `FacultyKey`
				;
			";
			mysql_query($query,$connection) or die(mysql_error()); 
		}
		echo "<br/>indexes disabled ... <br/>";
	}
	if ($vynimka) {		// BOOK					OK
		$query = "TRUNCATE `dwh`.`book`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`book` SELECT * FROM `ods`.`book` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'book' ... <br/>";
	}
	if ($vynimka) {		// COMPUTER				OK
		$query = "TRUNCATE `dwh`.`computer`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`computer` SELECT * FROM `ods`.`computer` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'computer' ... <br/>";
	}
	if ($vynimka) {		// LIBRARY				OK
		$query = "TRUNCATE `dwh`.`library`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`library` SELECT * FROM `ods`.`library` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'library' ... <br/>";
	}
	if ($vynimka) {		// FACULTY				OK
		$query = "TRUNCATE `dwh`.`faculty`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`faculty` SELECT * FROM `ods`.`faculty` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'faculty' ... <br/>";
	}
	if ($vynimka) {		// FIELDOFSTUDY			OK
		$query = "TRUNCATE `dwh`.`fieldofstudy`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`fieldofstudy` SELECT * FROM `ods`.`fieldofstudy` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'fieldofstudy' ... <br/>";
	}
	if ($vynimka) {		// AGGREGATERATINGS		OK
		$query = "TRUNCATE `dwh`.`aggregateratings`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`aggregateratings` SELECT * FROM `ods`.`aggregateratings` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'aggregateratings' ... <br/>";
	}
	if ($vynimka) {		// LIBRARYACCOUNT		OK
		$query = "TRUNCATE `dwh`.`libraryaccount`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`libraryaccount` SELECT * FROM `ods`.`libraryaccount` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'libraryaccount' ... <br/>";
	}
	if ($vynimka) {		// USERACCOUNT			OK
		$query = "TRUNCATE `dwh`.`useraccount`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`useraccount` SELECT * FROM `ods`.`useraccount` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'useraccount' ... <br/>";
	}
	if ($vynimka) {		// STUDYSTATUS			OK
		$query = "TRUNCATE `dwh`.`studystatus`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`studystatus` SELECT * FROM `ods`.`studystatus` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'studystatus' ... <br/>";
	}
	if ($vynimka) {		// TERM					OK
		$query = "TRUNCATE `dwh`.`term`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`term` SELECT * FROM `ods`.`term` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'term' ... <br/>";
	}
	if ($vynimka) {		// EXAMFACTS			OK
		$query = "TRUNCATE `dwh`.`examfacts`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`examfacts` SELECT * FROM `ods`.`examfacts` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'examfacts' ... <br/>";
	}
	if ($vynimka) {		// TIME					OK
		$query = "TRUNCATE `dwh`.`time`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`time` SELECT * FROM `ods`.`time` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'time' ... <br/>";
	}
	if ($vynimka) {		// SESSIONFACTS			OK
		$query = "TRUNCATE `dwh`.`sessionfacts`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`sessionfacts` SELECT * FROM `ods`.`sessionfacts` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'sessionfacts' ... <br/>";
	}
	if ($vynimka) {		// ROOM					OK
		$query = "TRUNCATE `dwh`.`room`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`room` SELECT * FROM `ods`.`room` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'room' ... <br/>";
	}
	if ($vynimka) {		// COURSE				OK
		$query = "TRUNCATE `dwh`.`course`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`course` SELECT * FROM `ods`.`course` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'course' ... <br/>";
	}
	if ($vynimka) {		// EXAMTYPE				OK
		$query = "TRUNCATE `dwh`.`examtype`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`examtype` SELECT * FROM `ods`.`examtype` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'examtype' ... <br/>";
	}
	if ($vynimka) {		// BORROWINGFACTS 		OK
		$query = "TRUNCATE `dwh`.`borrowingfacts`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`borrowingfacts` SELECT * FROM `ods`.`borrowingfacts` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'borrowingfacts' ... <br/>";
	}
	if ($vynimka) {		// STUDENT				OK
		$query = "TRUNCATE `dwh`.`student`;" ;
		mysql_query($query,$connection)or die(mysql_error()); 
		$query = "INSERT `dwh`.`student` SELECT * FROM `ods`.`student` NOLOGGING;";
		if ($truncateAndInsert) mysql_query($query,$connection)or die(mysql_error());
		echo "copying table 'student' ... <br/>";
	}
	if (true){			// VYRIESIT PROBLEMY
		echo "riesim problemy <br/>";
		
		// JE TAM RIADOK MARTIN MIHALOVIC
		$query = "DELETE FROM `dwh`.`useraccount` WHERE `StudentKey` = 0";
		$answr = mysql_query($query,$connection) or die(mysql_error());

		// NETREBA, UZ TAM NIE SU TAKE
		$query = "DELETE FROM `dwh`.`borrowingfacts` WHERE `LibraryAccountKey` < 49";
		$answr = mysql_query($query,$connection) or die(mysql_error());
		
		//TIEZ NETREBA, PETO NIECO ZMENIL TAKZE UZ TAM NIE SU WHERE `FieldOfStudyKey` = 0 ";
		$query = " SELECT `StudentKey` FROM `dwh`.`student` WHERE `FieldOfStudyKey` = 0 ";
		$answr = mysql_query($query,$connection) or die(mysql_error());
		while($data = mysql_fetch_array($answr)) {
			//echo "Odstranujem studenta cislo " . $data['StudentKey'] . "<br>";
			
			//useraccount
			$query2 = " SELECT `UserAccountKey` FROM `dwh`.`useraccount` WHERE `StudentKey` = ".$data['StudentKey'];
			$answr2 = mysql_query($query2,$connection) or die(mysql_error());
			while($data2 = mysql_fetch_array($answr2)) {
				//echo "  Odstranujem usera cislo " . $data2['UserAccountKey'] . "<br>";

				$query3 = "DELETE FROM `dwh`.`sessionfacts` WHERE `UserAccountKey` = " . $data2['UserAccountKey'];
				$answr3 = mysql_query($query3,$connection) or die(mysql_error());
						
				$query3 = "DELETE FROM `dwh`.`useraccount` WHERE `UserAccountKey` = " . $data2['UserAccountKey'];
				$answr3 = mysql_query($query3,$connection) or die(mysql_error());
			}
			
			//aggregateratings
			$query2 = "DELETE FROM `dwh`.`aggregateratings` WHERE `StudentKey` = ".$data['StudentKey'];
			$answr2 = mysql_query($query2,$connection) or die(mysql_error());

			//libraryaccount
			$query2 = " SELECT `LibraryAccountKey` FROM `dwh`.`libraryaccount` WHERE `StudentKey` = ".$data['StudentKey'];
			$answr2 = mysql_query($query2,$connection) or die(mysql_error());
			while($data2 = mysql_fetch_array($answr2)) {
				//echo "  Odstranujem library account cislo " . $data2['LibraryAccountKey'] . "<br>";

				$query3 = "DELETE FROM `dwh`.`borrowingfacts` WHERE `LibraryAccountKey` = ".$data2['LibraryAccountKey'];
				$answr3 = mysql_query($query3,$connection) or die(mysql_error());
				
				$query3 = "DELETE FROM `dwh`.`libraryaccount` WHERE `LibraryAccountKey` = ".$data2['LibraryAccountKey'];
				$answr3 = mysql_query($query3,$connection) or die(mysql_error());
			}
			
			//examfacts
			$query2 = "DELETE FROM `dwh`.`examfacts` WHERE `StudentKey` = ".$data['StudentKey'];
			$answr2 = mysql_query($query2,$connection) or die(mysql_error());

			//examfacts
			$query2 = "DELETE FROM `dwh`.`student` WHERE `StudentKey` = ".$data['StudentKey'];
			$answr2 = mysql_query($query2,$connection) or die(mysql_error());
		}
		echo "problemy vyriesene <br/>";
	}
	if (true) {			// HODIME INDEXY SPAT
		echo "enabling indexes ... ";
		{	//LIBRARY
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`library` 
					ADD CONSTRAINT `FacultyKey`
					FOREIGN KEY (`FacultyKey` )
					REFERENCES `dwh`.`faculty` (`FacultyKey` )
					ON DELETE NO ACTION
					ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//LIBRARYACCOUNT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`libraryaccount` 
					ADD CONSTRAINT `fk_LibraryAccount_Time1`
						FOREIGN KEY (`CreationTimeKey` )
							REFERENCES `dwh`.`time` (`TimeKey` )
						ON UPDATE NO ACTION
						ON DELETE NO ACTION, 
					ADD CONSTRAINT `fk_LibAccount_Student`
						FOREIGN KEY (`StudentKey` )
							REFERENCES `dwh`.`student` (`StudentKey` )
						ON UPDATE NO ACTION
						ON DELETE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//STUDENT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`student` 
					ADD CONSTRAINT `fk_Student_StudyStatus1`
						FOREIGN KEY (`StudyStatusKey` )
							REFERENCES `dwh`.`studystatus` (`StudyStatusKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_Student_FieldOfStudy1`
						FOREIGN KEY (`FieldOfStudyKey` )
							REFERENCES `dwh`.`fieldofstudy` (`FieldOfStudyKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//USERACCOUNT
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`useraccount` 
					ADD CONSTRAINT `fk_UserAccount_Student1`
						FOREIGN KEY (`StudentKey` )
							REFERENCES `dwh`.`student` (`StudentKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//BORROWINGFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`borrowingfacts` 
					ADD CONSTRAINT `fk_BorrowingFacts_Book1`
						FOREIGN KEY (`BookKey` )
							REFERENCES `dwh`.`book` (`BookKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_BorrowingFacts_Library1`
						FOREIGN KEY (`LibraryKey` )
							REFERENCES `dwh`.`library` (`LibraryKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_BorrowingFacts_LibraryAccount1`
						FOREIGN KEY (`LibraryAccountKey` )
							REFERENCES `dwh`.`libraryaccount` (`LibraryAccountKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_BorrowingFacts_Time1`
						FOREIGN KEY (`StartTimeKey` )
							REFERENCES `dwh`.`time` (`TimeKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_BorrowingFacts_Time2`
						FOREIGN KEY (`EndTimeKey` )
							REFERENCES `dwh`.`time` (`TimeKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//AGGREGATERATINGS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`aggregateratings` 
					ADD CONSTRAINT `fk_AggregateRatings_Student1`
						FOREIGN KEY (`StudentKey` )
							REFERENCES `dwh`.`student` (`StudentKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_AggregateRatings_Term1`
						FOREIGN KEY (`StartTermKey` )
							REFERENCES `dwh`.`term` (`TermKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_AggregateRatings_Term2`
						FOREIGN KEY (`EndTermKey` )
							REFERENCES `dwh`.`term` (`TermKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//COMPUTER
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`computer` 
					ADD CONSTRAINT `fk_Computer_Room1`
						FOREIGN KEY (`RoomKey` )
							REFERENCES `dwh`.`room` (`RoomKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//SESSIONFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`sessionfacts` 
					ADD CONSTRAINT `fk_SessionFacts_Computer1`
						FOREIGN KEY (`ComputerKey` )
							REFERENCES `dwh`.`computer` (`ComputerKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_SessionFacts_Room1`
						FOREIGN KEY (`RoomKey` )
							REFERENCES `dwh`.`room` (`RoomKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_SessionFacts_Time1`
						FOREIGN KEY (`StartTimeKey` )
							REFERENCES `dwh`.`time` (`TimeKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_SessionFacts_Time2`
						FOREIGN KEY (`EndTimeKey` )
							REFERENCES `dwh`.`time` (`TimeKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_SessionFacts_UserAccount1`
						FOREIGN KEY (`UserAccountKey` )
							REFERENCES `dwh`.`useraccount` (`UserAccountKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		{	//EXAMFACTS
			echo "> ";
			$query = "
				ALTER TABLE `dwh`.`examfacts` 
					ADD CONSTRAINT `fk_ExamFacts_Terms1`
						FOREIGN KEY (`TermKey` )
							REFERENCES `dwh`.`term` (`TermKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_ExamFacts_Student1`
						FOREIGN KEY (`StudentKey` )
							REFERENCES `dwh`.`student` (`StudentKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_ExamFacts_Room1`
						FOREIGN KEY (`RoomKey` )
							REFERENCES `dwh`.`room` (`RoomKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_ExamFacts_ExamType1`
						FOREIGN KEY (`ExamTypeKey` )
							REFERENCES `dwh`.`examtype` (`ExamTypeKey` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION, 
					ADD CONSTRAINT `fk_ExamFacts_Course1`
						FOREIGN KEY (`CourseKey` )
							REFERENCES `dwh`.`course` (`idCourse` )
						ON DELETE NO ACTION
						ON UPDATE NO ACTION
				;
			";
			mysql_query($query,$connection)or die(mysql_error()); 
		}
		echo "<br/>indexes enabled ... <br/>";
	}	
	echo "end " . date("i:s:u") . "<br/>";

?>
</body>
</html>





















